let g:plug_file_path = "~/AppData/Local/nvim/plugged"

call plug#begin(plug_file_path)
" Plug 'brglng/vim-im-select'
" Plug 'autozimu/LanguageClient-neovim', {
" \ 'branch': 'next',
" \ 'do': 'bash install.sh',
" \ }

" 自动格式化工具
Plug 'Chiel92/vim-autoformat'
Plug 'martinda/Jenkinsfile-vim-syntax'
Plug 'sbdchd/neoformat'
" latex编辑
" Plug 'lervag/vimtex'


" 文件树
"Plug 'nvim-tree/nvim-web-devicons' " optional
" Plug 'nvim-tree/nvim-tree.lua'

" Plug 'vim-scripts/taglist.vim'
" 在浏览器中使用nvim
" Plug 'glacambre/firenvim', { 'do': { _ -> firenvim#install(0) } }
" " (Optional) Multi-entry selection UI.
Plug 'junegunn/fzf'
" Plug 'easymotion/vim-easymotion'
Plug 'Lokaltog/vim-easymotion'
" Plug 'https://gitcode.net/BlueSky4_19/vifm.vim'
" Plug 'Raimondi/delimitMate'
" Plug 'https://gitcode.net/mirrors/jiangmiao/auto-pairs.git'
Plug 'jiangmiao/auto-pairs'
Plug 'https://gitcode.net/BlueSky4_19/vim-markbar.git'
" Plug 'https://gitcode.net/mirrors/rbgrouleff/bclose.vim.git'
Plug 'rbgrouleff/bclose.vim'
" Plug 'francoiscabrol/ranger.vim'
" Plug 'vim-scripts/fcitx.vim'
Plug 'vim-airline/vim-airline'
Plug 'connorholyday/vim-snazzy'
Plug 'sickill/vim-monokai'
Plug 'phanviet/vim-monokai-pro'
" Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" Plug 'Xuyuanp/nerdtree-git-plugin'

" Taglist
" Plug 'majutsushi/tagbar.git', { 'on': 'TagbarOpenAutoClose' }
Plug 'preservim/tagbar', { 'on': 'TagbarOpenAutoClose' }

" Error checking
"Plug 'w0rp/ale'

" Auto Complete
"Plug 'Valloric/YouCompleteMe'

" Undo Tree
"Plug 'mbbill/undotree/'

" Other visual enhancement
" Plug 'nathanaelkane/vim-indent-guides'
"Plug 'itchyny/vim-cursorword'

" Git
" Plug 'rhysd/conflict-marker.vim'
" Plug 'tpope/vim-fugitive'
" Plug 'mhinz/vim-signify'
" Plug 'gisphm/vim-gitignore', { 'for': ['gitignore', 'vim-plug'] }

" HTML, CSS, JavaScript, PHP, JSON, etc.
Plug 'https://gitcode.net/BlueSky4_19/vim-json.git'
Plug 'https://gitcode.net/BlueSky4_19/vim-css3-syntax.git'
Plug 'https://gitcode.net/BlueSky4_19/piv.git', { 'for' :['php', 'vim-plug'] }
Plug 'gko/vim-coloresque', { 'for': ['vim-plug', 'php', 'html', 'javascript', 'css', 'less'] }
Plug 'pangloss/vim-javascript', { 'for' :['javascript', 'vim-plug'] }
"Plug 'https://gitcode.net/mirrors/mattn/emmet-vim.git'

" Python
" Plug 'vim-scripts/indentpython.vim'

" Markdown
" 会强制折叠，不好用
" Plug 'joker1007/vim-markdown-quote-syntax'
" markdown的高亮，可以设置代码块高亮，但似乎没必要
" Plug 'https://gitcode.net/mirrors/tpope/vim-markdown.git'
" Plug 'suan/vim-instant-markdown', {'for': 'markdown'}
" Plug 'instant-markdown/vim-instant-markdown', {'for': 'markdown'}
" Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install_sync() }, 'for' :['markdown', 'vim-plug'] }
Plug 'dhruvasagar/vim-table-mode', { 'on': 'TableModeToggle' }
Plug 'https://gitcode.net/mirrors/vimwiki/vimwiki.git'

" Bookmarks
" Plug 'kshenoy/vim-signature'

" Go
" vim-go插件导致保存时文件光标错位，对neovim支持不好
" Plug 'fatih/vim-go' , { 'for': ['go', 'vim-plug'], 'tag': '*' }
Plug 'tweekmonster/gofmt.vim'

" Other useful utilities
"Plug 'terryma/vim-multiple-cursors'
Plug 'https://gitcode.net/BlueSky4_19/limelight.vim'
Plug 'junegunn/goyo.vim' " distraction free writing mode
Plug 'tpope/vim-surround' " type ysks' to wrap the word with '' or type cs'` to change 'word' to `word`
Plug 'godlygeek/tabular' " type ;Tabularize /= to align the =
Plug 'gcmt/wildfire.vim' " in Visual mode, type i' to select all text in '', or type i) i] i} ip
" Plug 'scrooloose/nerdcommenter' " in <space>cc to comment a line
" Plug 'ludovicchabant/vim-gutentags'
" Dependencies
Plug 'MarcWeber/vim-addon-mw-utils'
" Plug 'https://gitcode.net/mirrors/kana/vim-textobj-user.git'
" Plug 'fadein/vim-FIGlet'
" Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'neoclide/coc.nvim', {'branch': 'release'}
"Plug 'honza/vim-snippets'
Plug 'tpope/vim-commentary'

"snippet
" Plug 'SirVer/ultisnips'

call plug#end()

" let g:airline_powerline_fonts = 1
" let g:airline#extensions#tabline#enabled = 1

source ~/AppData/Local/nvim/coc.config.vim

" \ 'coc-tailwindcss',
" let g:coc_global_extensions = [
"     \ 'coc-go',
"     \ 'coc-tsserver',
"     \ 'coc-css',
"     \ 'coc-vimtex',
"     \ 'coc-diagnostic',
"     \ 'coc-eslint',
"     \ 'coc-flutter-tools',
"     \ 'coc-gitignore',
"     \ 'coc-html',
"     \ 'coc-import-cost',
"     \ 'coc-json',
"     \ 'coc-lists',
"     \ 'coc-prettier',
"     \ 'coc-pyright',
"     \ 'coc-snippets',
"     \ 'coc-sourcekit',
"     \ 'coc-stylelint',
"     \ 'coc-syntax',
"     \ 'coc-tasks',
"     \ 'coc-tslint-plugin',
"     \ 'coc-vetur',
"     \ 'coc-vimlsp',
"     \ 'coc-yaml',
"     \ 'coc-yank']

" \ !pumvisible() ? \"\<TAB>" :
" inoremap <silent><expr> <TAB>
" \ pumvisible()  ? "\<C-n>" :
" \ Check_back_space() ? "\<TAB>" :
" \ coc#refresh()

" inoremap <silent><expr> <TAB>
" \ coc#pum#visible() ? coc#_select_confirm() :
" \ coc#expandableOrJumpable() ? \"\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
" \ CheckBackspace() ? "\<TAB>" :
" \ coc#refresh()

" function! CheckBackspace() abort
" let col = col('.') - 1
" return !col || getline('.')[col - 1]  =~# '\s'
" endfunction

" let g:coc_snippet_next = '<tab>'

" inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

" inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"


" function! Check_back_space() abort
"   let col = col('.') - 1
"     return !col || getline('.')[col - 1]  =~# '\s'
" endfunction

" nmap <silent> <LEADER>- <Plug>(coc-diagnostic-prev)
" nmap <silent> <LEADER>+ <Plug>(coc-diagnostic-next)
" autocmd CursorHold * silent call CocActionAsync('highlight')

" function! Show_documentation()
"     call CocActionAsync('highlight')
"     if (index(['vim','help'], &filetype) >= 0)
"       execute 'h '.expand('<cword>')
"     else
"       call CocAction('doHover')
"     endif
" endfunction

" nnoremap <LEADER>h :call Show_documentation()<CR>
" nnoremap <LEADER>c :CocCommand<CR>
" nnoremap <nowait> <silent> <LEADER>sn :set splitright<CR>:vsplit<CR>:CocCommand snippets.editSnippets<CR>
" nnoremap <LEADER>sn :CocCommand snippets.editSnippets<CR>
" Text Objects
"xmap kf <Plug>(coc-funcobj-i)
"xmap af <Plug>(coc-funcobj-a)
"omap kf <Plug>(coc-funcobj-i)
"omap af <Plug>(coc-funcobj-a)
"xmap kc <Plug>(coc-classobj-i)
"omap kc <Plug>(coc-classobj-i)
"xmap ac <Plug>(coc-classobj-a)
"omap ac <Plug>(coc-classobj-a)
"" Useful commands
" nnoremap <silent> <space>y :<C-u>CocList -A --normal yank<cr>
" nmap <silent> gd <Plug>(coc-definition)
" nmap <silent> gy <Plug>(coc-type-definition)
" nmap <silent> gi <Plug>(coc-implementation)
" nmap <silent> gr <Plug>(coc-references)
" nmap <leader>rn <Plug>(coc-rename)
"nmap ff :CocCommand explorer<CR>
" coc-translator
" nmap <LEADER>dd <Plug>(coc-translator-p)
" Remap for do codeAction of selected region
" function! s:cocActionsOpenFromSelected(type) abort
" execute 'CocCommand actions.open ' . a:type
" endfunction
" xmap <leader>a  <Plug>(coc-codeaction-selected)
" nmap <leader>aw  <Plug>(coc-codeaction-selected)w
" coctodolist
" nnoremap <leader>tn :CocCommand todolist.create<CR>
" nnoremap <leader>tl :CocList todolist<CR>
" nnoremap <leader>tu :CocCommand todolist.download<CR>:CocCommand todolist.upload<CR>
" coc-tasks
" noremap <silent> <leader>ts :CocList tasks<CR>

try
    let g:SnazzyTransparent = 1
    color snazzy
catch
    color default
endtry


" coc-snippets
" Use <C-l> for trigger snippet expand.
" imap <C-l> <Plug>(coc-snippets-expand)

" Use <C-j> for select text for visual placeholder of snippet.
" vmap <C-j> <Plug>(coc-snippets-select)

" Use <C-j> for jump to next placeholder, it's default of coc.nvim
let g:coc_snippet_next = '<a-e>'

" Use <C-k> for jump to previous placeholder, it's default of coc.nvim
let g:coc_snippet_prev = '<a-u>'

let g:NERDTreeMapOpenSplit = 's'

"
" Use <leader>x for convert visual selected code to snippet
xmap <leader>x  <Plug>(coc-convert-snippet)

" ===
" === vim-instant-markdown
" ===
" let g:instant_markdown_slow = 0
" let g:instant_markdown_autostart = 0
" let g:instant_markdown_open_to_the_world = 1
" let g:instant_markdown_allow_unsafe_content = 1
" let g:instant_markdown_allow_external_content = 0
" let g:instant_markdown_mathjax = 1
" let g:instant_markdown_autoscroll = 1
" let g:instant_markdown_browser = "google-chrome-stable --new-window"

let g:vimwiki_list = [{'path': '~/vimwiki/',
\ 'syntax': 'markdown', 'ext': '.md'}]

" easymotion
"
let g:EasyMotion_do_mapping=0
nmap s <Plug>(easymotion-s2)
vmap s <Plug>(easymotion-s2)
let g:EasyMotion_inc_highlight= 0
let g:EasyMotion_landing_highlight = 0
let g:EasyMotion_smartcase = 1
" let g:EasyMotion_off_screen_search = 0

" autopair
" let g:AutoPairsShortcutJump = '<M-i>'
let g:AutoPairsShortcutJump = '<M-0>'
let g:AutoPairsShortcutToggle = ''
let g:AutoPairsShortcutFastWrap = ''

" fzf
let g:fzf_buffers_jump = 1
""" nerdtree {{{
"let g:NERDTreeMapCustomOpen      = get(g:, 'NERDTreeMapCustomOpen',      '<CR>')
"let g:NERDTreeMapActivateNode    = get(g:, 'NERDTreeMapActivateNode',    'o')
"let g:NERDTreeMapChangeRoot      = get(g:, 'NERDTreeMapChangeRoot',      'C')
"let g:NERDTreeMapChdir           = get(g:, 'NERDTreeMapChdir',           'cd')
"let g:NERDTreeMapCloseChildren   = get(g:, 'NERDTreeMapCloseChildren',   'X')
"let g:NERDTreeMapCloseDir        = get(g:, 'NERDTreeMapCloseDir',        'x')
"let g:NERDTreeMapDeleteBookmark  = get(g:, 'NERDTreeMapDeleteBookmark',  'D')
"let g:NERDTreeMapMenu            = get(g:, 'NERDTreeMapMenu',            'm')
"let g:NERDTreeMapHelp            = get(g:, 'NERDTreeMapHelp',            '?')
"let g:NERDTreeMapJumpParent      = get(g:, 'NERDTreeMapJumpParent',      'p')
"let g:NERDTreeMapJumpRoot        = get(g:, 'NERDTreeMapJumpRoot',        'P')
"let g:NERDTreeMapOpenExpl        = get(g:, 'NERDTreeMapOpenExpl',        'j')
"let g:NERDTreeMapOpenInTab       = get(g:, 'NERDTreeMapOpenInTab',       'ta')
"let g:NERDTreeMapOpenInTabSilent = get(g:, 'NERDTreeMapOpenInTabSilent', 'T')
"let g:NERDTreeMapOpenRecursively = get(g:, 'NERDTreeMapOpenRecursively', 'O')
"let g:NERDTreeMapOpenSplit       = get(g:, 'NERDTreeMapOpenSplit',       'S')
"let g:NERDTreeMapOpenVSplit      = get(g:, 'NERDTreeMapOpenVSplit',      's')
"let g:NERDTreeMapPreview         = get(g:, 'NERDTreeMapPreview',         'g'.NERDTreeMapActivateNode)
"let g:NERDTreeMapPreviewSplit    = get(g:, 'NERDTreeMapPreviewSplit',    'g'.NERDTreeMapOpenSplit)
"let g:NERDTreeMapPreviewVSplit   = get(g:, 'NERDTreeMapPreviewVSplit',   'g'.NERDTreeMapOpenVSplit)
"let g:NERDTreeMapQuit            = get(g:, 'NERDTreeMapQuit',            'q')
"let g:NERDTreeMapRefresh         = get(g:, 'NERDTreeMapRefresh',         'r')
"let g:NERDTreeMapRefreshRoot     = get(g:, 'NERDTreeMapRefreshRoot',     'R')
"let g:NERDTreeMapToggleBookmarks = get(g:, 'NERDTreeMapToggleBookmarks', 'B')
"let g:NERDTreeMapToggleFiles     = get(g:, 'NERDTreeMapToggleFiles',     'F')
"let g:NERDTreeMapToggleFilters   = get(g:, 'NERDTreeMapToggleFilters',   'f')
"let g:NERDTreeMapToggleHidden    = get(g:, 'NERDTreeMapToggleHidden',    'I')
"let g:NERDTreeMapToggleZoom      = get(g:, 'NERDTreeMapToggleZoom',      'A')
"let g:NERDTreeMapUpdir           = get(g:, 'NERDTreeMapUpdir',           'n')
"let g:NERDTreeMapUpdirKeepOpen   = get(g:, 'NERDTreeMapUpdirKeepOpen',   'N')
"let g:NERDTreeMapCWD             = get(g:, 'NERDTreeMapCWD',             'CD')
"let g:NERDTreeMenuDown           = get(g:, 'NERDTreeMenuDown',           'e')
"let g:NERDTreeMapJumpLastChild   = get(g:, 'NERDTreeMapJumpLastChild',   'E')
"let g:NERDTreeMapJumpNextSibling = get(g:, 'NERDTreeMapJumpNextSibling', '<C-e>')
"let g:NERDTreeMenuUp             = get(g:, 'NERDTreeMenuUp',             'u')
"let g:NERDTreeMapJumpFirstChild  = get(g:, 'NERDTreeMapJumpFirstChild',  'U')
"let g:NERDTreeMapJumpPrevSibling = get(g:, 'NERDTreeMapJumpPrevSibling', '<C-u>')
"""}}}
"
" let g:blamer_enabled = 1
let g:blamer_delay = 0
" limelight
" Color name (:help cterm-colors) or ANSI code
let g:limelight_conceal_ctermfg = 'gray'
let g:limelight_conceal_ctermfg = 240

" Color name (:help gui-colors) or RGB color
let g:limelight_conceal_guifg = 'DarkGray'
let g:limelight_conceal_guifg = '#777777'

" Default: 0.5
let g:limelight_default_coefficient = 0.7

" Number of preceding/following paragraphs to include (default: 0)
let g:limelight_paragraph_span = 1

" Beginning/end of paragraph
"   When there's no empty line between the paragraphs
"   and each paragraph starts with indentation
let g:limelight_bop = '^\s'
let g:limelight_eop = '\ze\n^\s'

" Highlighting priority (default: 10)
"   Set it to -1 not to overrule hlsearch
let g:limelight_priority = -1

" goyo
let g:goyo_width=80
let g:goyo_height=85
let g:goyo_linenr=10

nnoremap zz :Goyo<cr>
function! s:goyo_enter()
    set number
    noremap <nowait> <LEADER>nn :Goyo<cr>:call Compile()<CR>
    noremap <nowait> <LEADER>ne :Goyo<cr>:call CompileAndRun()<CR>
    noremap <nowait> <LEADER>hh :Goyo<cr>:call Debug()<CR>
    noremap <LEADER>ee :Goyo<cr>:call ZzxRun()<CR>
    noremap <LEADER>en :Goyo<cr>:call ZzxRedirectRun()<CR>
    " Limelight
endfunction

function! s:goyo_leave()
    noremap <nowait> <LEADER>nn :call Compile()<CR>
    noremap <nowait> <LEADER>ne :call CompileAndRun()<CR>
    noremap <nowait> <LEADER>hh :call Debug()<CR>
    noremap <LEADER>ee :call ZzxRun()<CR>
    noremap <LEADER>en :call ZzxRedirectRun()<CR>
    " Limelight!
    set cursorline
endfunction

autocmd! User GoyoEnter nested call <SID>goyo_enter()
autocmd! User GoyoLeave nested call <SID>goyo_leave()
" coc-explorer

" vimtex
" let g:tex_flavor = 'latex'

" let g:vimtex_quickfix_mode = 0
" settings for sumatraPDF
" let g:vimtex_view_general_viewer = 'SumatraPDF'
" let g:vimtex_view_general_options
"     \ = '-reuse-instance -forward-search @tex @line @pdf'
" let g:vimtex_view_general_options_latexmk = '-reuse-instance'
" let g:vimtex_view_general_options
" \ = '-reuse-instance -forward-search @tex @line @pdf'
" let g:vimtex_view_general_options_latexmk = '-reuse-instance'

" gofmt.vim
let g:gofmt_exe = 'goimports.exe'




" inoremap <silent><expr> <C-e> coc#pum#visible() ? coc#pum#cancel() : "\<C-e>"
" inoremap <silent><expr> <C-y> coc#pum#visible() ? coc#pum#confirm() : "\<C-y>"

" function! CheckBackspace() abort
"   let col = col('.') - 1
"   return !col || getline('.')[col - 1]  =~ '\s'
" endfunction

" Insert <tab> when previous text is space, refresh completion if not.
" inoremap <silent><expr> <TAB>
"   \ coc#pum#visible() ? coc#pum#next(1):
"   \ CheckBackspace() ? "\<Tab>" :
"   \ coc#refresh()
" inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"

" inoremap <silent><expr> ,s
"   \ coc#pum#visible() ? coc#_select_confirm() :
"   \ coc#expandableOrJumpable() ?
"   \ "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
"   \ CheckBackspace() ? ",s" :
"   \ coc#refresh()

" vmap ,s <Plug>(coc-snippets-select)

" inoremap <silent><expr> <CR> coc#pum#visible() ? coc#_select_confirm()
              " \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"

" let g:coc_snippet_next = "<C-k>"
" let g:coc_snippet_prev = "<C-j>"

" vimwiki
let g:vimwiki_key_mappings =
  \ {
  \ 'table_mappings': '0'
  \ }


" vim-autoformat
let g:autoformat_verbosemode=1 "开启详细模式便于查错
" autocmd BufWrite *.java :Autoformat "设置发生保存事件时执行格式化
"let g:autoformat_autoindent = 0
"let g:autoformat_retab = 0
"let g:autoformat_remove_trailing_spaces = 0
"autocmd FileType vim,tex let b:autoformat_autoindent=0
"gg=G :retab :RemoveTrailingSpaces



let g:neoformat_enabled_groovy = ['groovy']
